//
// Created by xqyr on 2025/3/30.
//

#include "fclient.h"
#include "ftype.h"
FClient::FClient(const char *name, CBaseWorker *worker)
: CBaseClient(name, worker) {

}

void FClient::onOnline(FdbSessionId_t sid, bool is_first) {
    FDB_LOG_D("onOnline sid=%d, is_first=%d\n", sid, is_first);
    if (is_first) {
        /* add all events to subscribe list */
        CFdbMsgSubscribeList subscribe_list;
        addNotifyItem(subscribe_list, NTF_ELAPSE_TIME, "my_filter");
//        addNotifyItem(subscribe_list, NTF_ELAPSE_TIME, "raw_buffer");
//        addNotifyItem(subscribe_list, NTF_CJSON_TEST);
//        addNotifyGroup(subscribe_list, MEDIA_GROUP_1);
//        /*
//         * register NTF_MANUAL_UPDATE for manual update: it will not
//         * update unless update() is called
//         */
//        addUpdateItem(subscribe_list, NTF_MANUAL_UPDATE);
        /* subscribe them, leading to onSubscribe() to be called at server */
        subscribe(subscribe_list);
    }
}

void FClient::onOffline(FdbSessionId_t sid, bool is_last) {
    FDB_LOG_D("onOffline sid=%d, is_last=%d\n", sid, is_last);
}

void FClient::onBroadcast(CBaseJob::Ptr &msg_ref) {
    FDB_LOG_D("onBroadcast %xd\n",msg_ref.get());
}

void FClient::onReply(CBaseJob::Ptr &msg_ref) {
    FDB_LOG_D("onReply %xd \n",msg_ref.get());
}

void FClient::onStatus(CBaseJob::Ptr &msg_ref, int32_t error_code, const char *description) {
    auto msg = castToMessage<CBaseMessage *>(msg_ref);
    if (msg->isSubscribe())
    {
        if (msg->isError())
        {
        }
        else
        {
            FDB_LOG_I("subscribe is ok! sn: %d is received.\n", msg->sn());
        }
    }
    FDB_LOG_I("Reason: %s\n", description);
}

